@extends('layouts.admin')
@section('content')
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{url('admin/info')}}">首页</a> &raquo; <a href="{{url('admin/config')}}">网站配置管理</a> &raquo; 编辑配置项
    </div>
    <!--面包屑导航 结束-->
    
    <div class="result_wrap">
        <div class="result_title">
            <h3>编辑配置项</h3>
            @if(count($errors))
                <div class="mark">
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <p style="font-size:14px;font-weight:bold">{{$error}}</p>
                        @endforeach
                    @else
                        <p style="font-size:14px;font-weight:bold">{{$errors}}</p>
                    @endif
                </div>
            @endif
        </div>
        <form action="{{url('admin/config/'.$field->conf_id)}}" method="post">
            {{csrf_field()}}
            {{method_field('PUT')}}
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th><i class="require">*</i>配置名称：</th>
                        <td>
                            <input type="text" name="conf_title" value="{{$field->conf_title}}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>配置名称必须填写</span>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>变量名：</th>
                        <td>
                            <input type="text" name="conf_var" value="{{$field->conf_var}}" onchange="checkVar(this)">
                            <span><i class="fa fa-exclamation-circle yellow"></i>变量名必须填写,数字,字母,下划线的组合,不能以数字开头</span>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>类型：</th>
                        <td>
                            <label><input type="radio" name="input_type" value="input" @if($field->input_type == 'input') checked @endif onclick="showTr()">单行文本</label>
                            <label><input type="radio" name="input_type" value="textarea" onclick="showTr()" @if($field->input_type == 'textarea') checked @endif>多行文本</label>
                            <label><input type="radio" name="input_type" value="radio" onclick="showTr()" @if($field->input_type == 'radio') checked @endif>单选框</label>
                        </td>
                    </tr>
                    <tr class="type_value" style="display:none">
                        <th><i class="require">*</i>单选数据格式：</th>
                        <td>
                            <input type="text" class="md" name="type_value" value="{{$field->type_value}}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>只有radio类型填写,格式: 0:关闭|1:开启</span>
                        </td>
                    </tr>
                    <tr>
                        <th>变量值：</th>
                        <td>
                            <input type="text" class="md" name="conf_content" value="{{$field->content}}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>conf_content 字段的值</span>
                        </td>
                    </tr>
                    <tr>
                        <th>排序：</th>
                        <td>
                            <input type="text" class="sm" name="conf_order" value="{{$field->conf_order}}">
                        </td>
                    </tr>
                    <tr>
                        <th>注释：</th>
                        <td>
                            <textarea class="lg" style="max-height:50px" name="conf_comment"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <input type="submit" value="提交">
                            <input type="button" class="back" onclick="history.go(-1)" value="返回">
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
<script>
    showTr();
  function showTr(){
      var obj = $('input:checked');
       if(obj.val() == 'radio'){
           $('.type_value').show();
           $('input[name=conf_content]').val('0');
           $('input[name=type_value]').val('0:关闭|1:开启');

       }else{
           $('.type_value').hide();
           $('input[name=conf_content]').val('');
           $('input[name=type_value]').val('');
       }
  }

  function checkVar(obj){
      $.post(
              "{{url('admin/config/checkvar')}}",
              {'_token':"{{csrf_token()}}",'conf_var':obj.value},
              function(data){
                if(data.status == 1){
                    layer.alert(data.msg, {
                        icon: 5,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                    obj.value = '';
                }//endif
              }
      );
  }
</script>
@endsection